package com.suoluo.zenadmin.http;

import org.apache.commons.httpclient.HttpStatus;

import com.google.gson.Gson;

public class HttpResponse {

	private final int statusCode;
	
	private final String data;

	public HttpResponse(int statusCode, String data) {
		super();
		this.statusCode = statusCode;
		this.data = data;
	}
	
	public boolean isOK(){
		return statusCode == HttpStatus.SC_OK;
	}
	
	public String asString(){
		return data;
	}
	
//	public InputStream asStream(){
//		try {
//			return method.getResponseBodyAsStream();
////		} catch (IOException e) {
////			throw new HttpException(e);
////		}
//	}
	
	public <T> T asObject(Class<T> clazz){
		Gson gson = new Gson();
		String asString = asString();
		return gson.fromJson(asString, clazz);
	}
}
